<template>
	<view class="u-content">
		<u-parse :html="content"></u-parse>
		<u-input v-model="dowork" :type="type" :border="border" :height="height" :auto-height="autoHeight" :placeholder="answers" :disabled="true"></u-input>
		<u-gap height="10" bg-color="#c8c9cc"></u-gap>
		<u-input v-model="value" :type="type" :border="border" :height="height" :auto-height="autoHeight" />
		<u-button type="primary" :disabled = "opinion" :ripple="true" @click="doWork()">提交</u-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				content: '',
				dowork:'',
				value: '',
				type: 'textarea',
				border: true,
				height: 200,
				autoHeight: true,
				workid: "",
				coursename: "",
				opinion: false,
				answers: "答案"
			}
		},
		onLoad: function(op) {
			if (op) {
				console.log(op.workid);
				this.workid = op.workid;
				this.isdo();
			}
		},
		onReady() {
			this.getwork();
		},
		methods:{
			isdo() {
				this.$http('/isdo', {
					stuid: uni.getStorageSync("stuid"),
					workid: this.workid,
				})
				.then((res) =>{
					console.log(res);
					if (res.length) {
						this.opinion = true;
						this.answers = res[0].url;
						console.log(this.opinion);
						console.log(this.answers);
					}
				})
			},
			getwork() {
				this.$http('/stuworkbyid', {
					workid: this.workid
				})
				.then((res) => {
					console.log(res);
					this.content = res[0].worktext;
					this.coursename = res[0].coursename;
				})
			},
			doWork(){
				this.dowork = this.value;
				this.$http("/stuworkup", {
					stuid: uni.getStorageSync("stuid"),
					workid: this.workid,
					url: this.value,
					stuname: this.coursename
				})
				.then((res) =>{
					console.log(res);
					if (res.code == 200) {
						uni.redirectTo({
							url: "dowork?workid=" + this.workid,
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.u-content {
		margin-top: 10rpx;
		color: $u-content-color;
		font-size: 32rpx;
		line-height: 3;
		
		// 标签形式无效
		p {
			color: $u-tips-color;
		}
	}
</style>